/*
    Item.cpp

    Date:
        05-09-10

    Descripton:
        A contianer for individual calendar items

    Authors:
        Nathaniel Brown
        Subodh Prabhu
        Jesus Suarez
*/


/****************************************************************************/
/*                              I N C L U D E S                             */
/****************************************************************************/

#include "GlutHeaders.h"
#include "Item.h"


/****************************************************************************/
/*                      U T I L I Y   F U N C T I O N S                     */
/****************************************************************************/
	
ostream&operator<<(ostream &stream, Item o) {
  stream << o.title << " (";
  if(o.type==VEVENT) stream << "event";
  else if(o.type==VTODO) stream << "todo";
  string startT (ctime(&o.start));
  string endT (ctime(&o.end));
  stream << ")\n";
  stream << "    " << startT << " to\n    " << endT
         << "    " << "[" << o.description << "]\n";

  return stream;
}


/****************************************************************************/
/*               I T E M   :   M E M B E R   F U N C T I O N S              */
/****************************************************************************/

Item::Item() {
  title = "";
  description = "";
  level = 0;
}

bool
Item::setLevel(int level) {
  if(   level == APPOINTMENT
     || level == TASK
     || level == FUN_TIME
     || level == EVENT) {
    this->level = level;
    return true;
  }
  return false;
}

bool
Item::setType(int type) {
  if(type == VEVENT || type == VTODO) {
    this->type = type;
    return true;
  }
  return false;
}

bool
Item::setStartDate(time_t start) {
  this->start = start;
  return true;
}

bool
Item::setEndDate(time_t end) {
  this->end = end;
  return true;
}

bool
Item::setTitle(string title) {
  this->title = title;
  return true;
}

bool
Item::setDescription(string description) {
  this->description = description;
  return true;
}

int
Item::isValid() {
  if(type == VEVENT
     && strcmp(title.c_str(), "")
     && strcmp(ctime(&start), "")
     && strcmp(ctime(&end), ""))
    return VEVENT;

  else if(type == VTODO
          && strcmp(title.c_str(), "")
          && strcmp(ctime(&start), ""))
    return VTODO;

  return 0;
}

time_t
Item::getStartTime() {
  return start;
}

time_t
Item::getEndTime() {
  return end;
}

string
Item::getTitle() {
  return title;
}

string
Item::getDescription() {
  return description;
}

int
Item::getLevel() {
  return level;
}

int
Item::getType() {
  return type;
}

bool
Item::operator ()(Item x, Item y) {
  if(difftime(x.start, y.start) >= 0)
    return true;
  else
    return false;
}
